package com.yhtech.service.impl;

import java.io.Serializable;
import java.sql.Date;
import java.util.List;

import com.yhtech.bean.base.Corebase;
import com.yhtech.dao.IDAO;
import com.yhtech.exception.DAOException;
import com.yhtech.service.ICoreBaseService;
import com.yhtech.service.PropertyListener;
import com.yhtech.utils.PageBean;

public class CoreBaseServices implements ICoreBaseService<Corebase> {
	
	private IDAO dao;

	public IDAO getDao() {
		return dao;
	}

	public void setDao(IDAO dao) {
		this.dao = dao;
	}

	public boolean save(Corebase entity) {
		try {
             beforeSave(entity);			
			 dao.save(entity);
			 return true;
		} catch (Exception e) {
			throw new DAOException("�������ʱ���ִ�����ϸ��Ϣ���£�\n"+e.getMessage());
		}
	}

	public Corebase getValue(String id) {
		try {
			return  (Corebase) dao.getValue(id);
		} catch (Exception e) {
			throw new DAOException("��ȡ���ʱ���ִ�����ϸ��Ϣ���£�\n"+e.getMessage());
		}
	}

	public List<Corebase> getAll() {
		try {
			return  dao.getAll();
		} catch (Exception e) {
			throw new DAOException("��ȡ���ʱ���ִ�����ϸ��Ϣ���£�\n"+e.getMessage());
		}
	}

	public boolean update(Corebase entity) {
		try {
			  dao.update(entity);
			  return true;
		} catch (Exception e) {
			throw new DAOException("�޸����ʱ���ִ�����ϸ��Ϣ���£�\n"+e.getMessage());
		}
	}

	public List<Corebase> getAllByProperty(String propertyName, Serializable value) {
		try {
			return dao.getAllByProperty(propertyName, value);
		} catch (Exception e) {
			throw new DAOException("��ȡ���ʱ���ִ�����ϸ��Ϣ���£�\n"+e.getMessage());
		}
	}

	public List<Corebase> getAllByPageBean(PageBean pageBean) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<Corebase> getAllByPageBeanAndPropety(String propertyName, Serializable value, PageBean pageBean) {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean delete(String id) {
		try {
			  dao.delete(id);
			  return true;
		} catch (Exception e) {
			throw new DAOException("ɾ�����ʱ���ִ�����ϸ��Ϣ���£�\n"+e.getMessage());
		}
	}

	public List<Corebase> getAllByQuery(String[] property, Object[] values) {
		return dao.getAllByQuery(property, values);
	}

	public void beforeSave(Corebase entity) {
               entity.setCreateTime(new Date(System.currentTimeMillis()));	
               entity.setLastUpdateTime(new Date(System.currentTimeMillis()));
	}

}
